<?php

include_once( dirname(__FILE__).'/../basic/cfield.php' );

class CFAList extends CField #abstract
{
#-------------------------------------------------------------------------------------------------------------------------
	var $value_list 	= array();
	var $select_name	= '';

#-------------------------------------------------------------------------------------------------------------------------

	function __set_params( &$params ){
		parent :: __set_params( $params );
		$index = sizeof( $params['value_list'] );
		for($i=0; $i<$index; $i++){
			$value_list = array_change_key_case( $params['value_list'][$i], CASE_LOWER );
			$title = trim( $value_list['title'] );
			if ( $title ){
				$buf['title'] = $title;
				$buf['value'] = trim($value_list['value']);
				if ( intval($value_list[$this->select_name]) )
				    $buf[$this->select_name] = 1;
				$this->value_list[] = $buf;
				unset($buf);
			}
			unset($value_list);
		}
	}

#-------------------------------------------------------------------------------------------------------------------------

	function set_unique_vars( &$vars ){
		parent :: set_unique_vars( $vars );
		$vars['__value_list_'.$this->name] = $this->value_list;
	}

#-------------------------------------------------------------------------------------------------------------------------

	function set_value( $value ){
		$is_found = false;
		$index = sizeof($this->value_list);
		for($i=0; $i<$index; $i++){
			if ( $this->value_list[$i]['value'] == $value ){
				$this->value_list[$i][$this->select_name] = 1;
				$is_found = true;
			}else{				$this->value_list[$i][$this->select_name] = 0;
			}
		}
		parent :: set_value( $is_found ? $value : '' );
	}

#-------------------------------------------------------------------------------------------------------------------------

}

?>